package com.song.email.util.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Config {
	private static Log log = LogFactory.getLog(Config.class);
	private static Properties prop = new Properties();
	public static int isStart = 0;
	public static int sendFrequency = 30;
	public static int sendThreadNum = 5;
	public static String encoding = "UTF-8";
	public static String workFileName = "works.xml";
	public static String authFileName = "auths.xml";
	public static String mailtoList = "mailtoList.txt";
	public static int failRetryTimes = 3;

	static {
		InputStream inputStream = null;
		try {
			inputStream = new FileInputStream(new File(Config.class.getResource("/email.properties").getPath()));
			prop.load(inputStream);
			isStart = Integer.parseInt(prop.getProperty("isStart"));
			sendFrequency = Integer.parseInt(prop.getProperty("sendFrequency"));
			sendThreadNum = Integer.parseInt(prop.getProperty("sendThreadNum"));
			failRetryTimes = Integer.parseInt(prop.getProperty("failRetryTimes"));
			if(failRetryTimes<=0||failRetryTimes>20){
				failRetryTimes = 3;
			}
			encoding = prop.getProperty("encoding");
			workFileName = prop.getProperty("workFileName");
			authFileName = prop.getProperty("authFileName");
			mailtoList = prop.getProperty("mailtoList");
		} catch (IOException e1) {
			log.error("加载email.properties时出错...", e1);
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
